﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MaiMaConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           /* while (true)
            {
                var value = Console.ReadLine();

                //Console.WriteLine(value);

                //Calculate(Convert.Tolong32(value));
                Calculate2(Convert.ToInt32(value));
            }*/

            Console.WriteLine(FormatBytes(10243));
            Console.WriteLine(FormatBytes(102469));
            Console.WriteLine(FormatBytes(1024697));
            Console.ReadLine();
        }

        static string FormatBytes(long bytes)
        {
            string[] magnitudes = new string[] { "GB", "MB", "KB", "Bytes" };
            long max = (long)Math.Pow(1024, magnitudes.Length);
            var t1 = magnitudes.FirstOrDefault(magnitude => bytes > (max /= 1024)) ?? "0 Bytes";
            var t2 = ((decimal)bytes / (decimal)max);
            return string.Format("{1:##.##} {0}", t1, t2).Trim();
        }

        public static void Calculate(long num)
        {
            var shuang = 24;

            var total = 0L;
            for (long i = 1; i <= 10; i++)
            {
                var oneAmount = 24 * num;
                total += oneAmount;

                Console.WriteLine("24个数字购买{3}次消耗总金额={4}，中奖金额={2},本金={0}，盈利={1}", 24 * num, (40 * num) - 24 * num, 40 * num, i, total);
                Console.WriteLine((40 * num) - total);
            }

        }

        public static void Calculate1(long num)
        {
            var total = 0L;

            for (long i = 1; i <= num; i++)
            {
                var price = i * 10;
                var oneAmount = 24 * price;
                var d = 40 * price;
                total += oneAmount;
                Console.WriteLine("每个数字={1},成本={0}，中奖金额{2}", oneAmount, price, d);
                //Console.WriteLine("每个数字={2},成本={0},盈利={1}", total, (40 * price) - total,price);
            }
            Console.WriteLine("总成本={0}", total);



        }
        public static void Calculate2(long num)
        {
            var total = 0L;

            for (long i = 1; i <= num; i++)
            {
                var price = Get(1, total);

                var oneAmount = 24 * price;
                var oneTotal = 40 * price;
                total += oneAmount;

                Console.WriteLine("单次成本{2}每个数字{0} * 40 =最后一次中奖金额{1}", price, oneTotal, oneAmount);

                //Console.WriteLine("每个数字={1},成本={0}，中奖金额{2}", oneAmount, price, d);
            }
            Console.WriteLine("总成本={0}", total);

        }

        public static long Get(long price, long total)
        {
            if (40 * price - 24 * price - total > 100)
            {
                return price;
            }
            price = price + 1;
            return Get(price, total);
        }
    }
}
